package controll;

import dao.UserDao;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/getUser")
public class GetUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserDao ud=new UserDao();
        List<User> users=ud.findAll();
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out=resp.getWriter();
        out.write("<html><head><title>用户信息</title></head>");
        out.write("<body>");
        out.write("<table>");
        out.write("<tr><th>编号</th><th>姓名</th><th>密码</th><th>电话</th><th>图像</th></tr>");
        for (User u:users){
            out.write("<tr>");
            Object[] arr=u.toArray();
            for (int i=0;i<arr.length;i++){
                if(i<arr.length-1)
                    out.write("<td>"+arr[i]+"</td>");
                else
                    out.write("<td><img src=\""+arr[i]+"\" width='100'/></td>");
            }
            out.write("</tr>");
        }
        out.write("</table></body></html>");
        out.close();
    }
}
